package com.polaris.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.polaris.server.pojo.SysMenu;
import com.polaris.server.mapper.SysMenuMapper;
import com.polaris.server.service.ISysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author polaris
 * @since 2021-06-06
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {
    private final SysMenuMapper menuMapper;

    public SysMenuServiceImpl(SysMenuMapper menuMapper) {
        this.menuMapper = menuMapper;
    }

    /**
     * 获取menu列表
     * @return
     */
    @Override
    public List<SysMenu> queryAll() {
        return menuMapper.selectList(new QueryWrapper<SysMenu>());
    }
    /**
     * 通过id查询url
     * @param id
     * @return
     */
    @Override
    public String getUrlSet(Long id) {
        return menuMapper.selectOne(new QueryWrapper<SysMenu>().eq("id",id)).getUrl();
    }

    /**
     * 通过menuIdList查询对应的menuList
     * @param menuIdList
     * @return
     */
    @Override
    public List<SysMenu> getMenuList(List<Long> menuIdList) {
        List<SysMenu> menuList = new ArrayList<>();
        for (Long menuId : menuIdList) {
            SysMenu sysMenu = menuMapper.selectById(menuId);
            if(sysMenu!=null){
                menuList.add(sysMenu);
            }
        }
        return menuList;
    }
}
